import rlcompleter

class TossCompleter(rlcompleter.Completer):
    def __init__(self, task_names):
        self.task_names = task_names
    
    def complete(self, text, state):
        possible_completions = []
        for task_name in self.task_names:
            if task_name.startswith(text):
                possible_completions.append(task_name)
        if len(possible_completions) > 0:
            return possible_completions[state]
        #we only want to use the default if there are no matching tasks
        return rlcompleter.Completer.complete(self,text,state)
